﻿Imports System.IO
Imports System.Security.Cryptography
Imports System
Imports System.Text




Public Class CEncripcion

Public Shared Function Decrypt(ByVal strText As String, ByVal strEncrKey As String) As String
        Dim bKey As Byte() = New Byte(7) {}
        Dim IV As Byte() = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}

        Try
            bKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8))
            Dim des As New DESCryptoServiceProvider()
            Dim inputByteArray As Byte() = Convert.FromBase64String(strText)
            Dim ms As New MemoryStream()
            Dim cs As New CryptoStream(ms, des.CreateDecryptor(bKey, IV), CryptoStreamMode.Write)
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()
            Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8
            Return encoding.GetString(ms.ToArray())
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Public Shared Function Encrypt(ByVal strText As String, ByVal strEncrKey As String) As String
        Dim bKey As Byte() = New Byte(7) {}
        Dim IV As Byte() = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}

        Try
            bKey = System.Text.Encoding.UTF8.GetBytes(strEncrKey.Substring(0, 8))
            Dim des As New DESCryptoServiceProvider()
            Dim inputByteArray As Byte() = Encoding.UTF8.GetBytes(strText)
            Dim ms As New MemoryStream()
            Dim cs As New CryptoStream(ms, des.CreateEncryptor(bKey, IV), CryptoStreamMode.Write)
            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()

            Return Convert.ToBase64String(ms.ToArray())
        Catch ex As Exception
            Throw ex
        End Try
    End Function




End Class
